package com.knowif.backend.controller;

import com.knowif.backend.service.SchoolService;
import com.knowif.pojo.School;
import com.knowif.pojo.SchoolExample;
import com.knowif.search.SearchCondition;
import com.knowif.system.model.RestBean;
import com.knowif.util.ExampleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ：Xh
 * @date ：Created in 2019/6/10 0010 20:50
 */
@RestController
@RequestMapping("/wechat")
public class SchoolController {

    @Autowired
    private SchoolService schoolService;

    @PostMapping("/school/query")
    public RestBean<?> query(@RequestBody SearchCondition searchCondition){
        try {
            SchoolExample schoolExample = ExampleUtil.buildExample(new SchoolExample(), searchCondition);
            List<School> schools = schoolService.selectSchool(schoolExample, false);
            return RestBean.buildSuccess(schools);
        } catch (Exception e) {
            e.printStackTrace();
            return RestBean.buildError("参数错误");
        }
    }

}
